import { defineStore } from 'pinia'
import { ref } from 'vue'
import { Dialog, Snackbar } from '@varlet/ui'

export const SearchHistory = defineStore('history', () => {
    const historyArr = ref<string[]>([])
    const actions = {
        confirm: () => {
            Snackbar.success('删除成功')
            historyArr.value = []
        },
        cancel: () => Snackbar.error('cancel'),
        close: () => Snackbar.info('close'),
    }
    const setHistory = (value: string) => {
        if (historyArr.value.includes(value)) {
            return
        }
        historyArr.value.push(value)
    }
    const clearHistory = () => {
        async function createAction() {
            actions[await Dialog('是否要删除')]()
        }
        createAction()
        
    }
    return {
        historyArr,
        setHistory,
        clearHistory
    }
}, {
    persist: true,
})